Source Code Viewer - Example 4 - AbstractCompositeCache_2S

package name.matthewgreet.example4.common;

import java.io.Serializable;

import name.matthewgreet.example4.common.ListCache.ListCacheConfig;

/**
 * <P>Template for web level, session-based caching a master, record list with two slave lists for editing in various 
 *    web pages.  Subclasses of this, as well as defining the record types, typically set list finders and other 
 *    Strategies for record list relationships and pagination that clients don't set themselves, depending on web page 
 *    workflow.  Instances are typically created as Singletons.</P>
 *    
 * <DL>
 * <DT>KM</DT><DD>Type primary key of master records</DD>
 * <DT>TM</DT><DD>Type of master records</DD>
 * <DT>K1</DT><DD>Type primary key of slave list 1 records</DD>
 * <DT>T1</DT><DD>Type of slave list 1 records</DD>
 * <DT>K2</DT><DD>Type primary key of slave list 2 records</DD>
 * <DT>T2</DT><DD>Type of slave list 2 records</DD>
 * </DL>
 * 
 * <P>As there are a bewildering set of configuration options and client Struts actions are expected to know their 
 *    responsibilities in workflow, subclasses are a convenient Javadoc reference point for documenting this, such as 
 *    below.</P>
 * 
 */
public abstract class AbstractCompositeCache_2S<KM extends Serializable,TM extends Serializable,
                                                K1 extends Serializable,T1 extends Serializable,
                                                K2 extends Serializable,T2 extends Serializable> extends AbstractCompositeCache_1S<KM,TM,K1,T1> {
    private static final long serialVersionUID = -1843533976240270745L;
    
    private ListCache<TM,K2,T2> slaveList2;

    /**
     * Creates session-based, composite cache with a master list and 2 slave lists. 
     */
    protected AbstractCompositeCache_2S() {
        super();
        
        ListCacheConfig<TM,K2,T2> slaveListCacheConfig = getSlaveListCache2Config();
        slaveList2 = new ListCache<TM,K2,T2>(slaveListCacheConfig, getMasterListCache());
        slaveList2.addListCacheListener(listCache -> {notifySlaveListCache2Changed(listCache);});
    }
    

    /**
     * Overridden by concrete implementations to configure slave list cache 2. 
     */
    protected abstract ListCacheConfig<TM,K2,T2> getSlaveListCache2Config();
    
    
    /**
     * Notification that the slave list cache 2 has changed.
     */
    protected void notifySlaveListCache2Changed(ListCache<?,?,T2> listCache) {
        // Nothing but may be overridden.
    }

    /**
     * Returns cache of slave list 2. 
     */
    public ListCache<TM,K2,T2> getSlaveListCache2() {
        return slaveList2;
    }
    
}